package com.ihr360;

import com.ihr360.oneclick.filter.AuthUserResolver;
import feign.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;
import java.util.concurrent.Executor;

@EnableFeignClients
@SpringBootApplication
@EnableCircuitBreaker
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
@ComponentScan(basePackages = {"com.ihr360.oneclick","com.ihr360.admin","com.ihr360.rest","com.ihr360.message","com.ihr360.shared.encryption","cn.irenshi.db","cn.irenshi.redis","cn.irenshi.config","com.ihr360.mail"})
@PropertySource(value = "classpath:git.properties",ignoreResourceNotFound = true)
@EntityScan(basePackages = {"com.ihr360.oneclick.dto","com.ihr360.message.dto","com.ihr360.authority.sharing.model.dto","com.ihr360.mail.dto"})
@EnableJpaRepositories(basePackages = {"com.ihr360.oneclick.dao","com.ihr360.message","com.ihr360.authority.sharing.dao","com.ihr360.mail.dao"})
@EnableAsync
@ImportResource(locations = "classpath*:spring/redis-beans.xml")
public class Ihr360OneClickApplication extends WebMvcConfigurerAdapter {

	public static void main(String[] args) {
		SpringApplication.run(Ihr360OneClickApplication.class, args);
	}


	/**
	 * 修改feign的默认log级别，默认为NONE， 什么都不输出
	 *
	 * @return
	 */
	@Bean
	Logger.Level feignLoggerLevel() {
		return Logger.Level.FULL;
	}

	@Bean
	public Executor asyncExecutor() {
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
		executor.setCorePoolSize(50);
		executor.setMaxPoolSize(50);
		executor.setQueueCapacity(100);
		executor.setThreadNamePrefix("OneClick-asyncExecutor-");
		executor.initialize();
		return executor;
	}

	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
		super.addArgumentResolvers(argumentResolvers);
		argumentResolvers.add(new AuthUserResolver());
	}

}

